<template>
  <a-modal
    :title="title || '编辑'"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="ok()"
    @cancel="cancel()"
  >
    <a-spin :spinning="loading">
      <a-form ref="modalFormRef" :rules="rules" :form="form" v-bind="formLayout" >
        <a-form-item required has-feedback label="客户名称" name="name" :rules="[{ required: true, message: '请输入客户名称!' }]">
          <a-input v-model="form.name"/>
        </a-form-item>
        <a-form-item required has-feedback label="客户标识" name="clientSystem" :rules="[{ required: true, message: '请输入客户标识!' }]">
          <a-input v-model="form.clientSystem" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import Bus from '@/components/vue-simple-uploader/js/bus'
import GlobalUploader from '@/components/vue-simple-uploader/GlobalUploader'
import { mergeSimpleUpload,getQNToken } from '@/api/updata'
import * as qiniu from 'qiniu-js'

// 表单字段
const fields = ['description', 'id']

export default {
  components: {
    GlobalUploader
  },
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      form: {
        name:'',
        clientSystem:'',
      },

      platformList:[],
      MemoryList:[8,16,32],
      title:'',

      rules:{
        name: [{ required: true, message: '请输入客户名称',trigger: 'change,blur' }],
        clientSystem: [{ required: true, message: '请输入客户标识', trigger: 'change,blur' }],
      }
    }
  },
  created () {
    // console.log('custom modal created')

    // 防止表单未注册
    // fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.title = this.model.name
      this.form = this.model
      console.log('%c [ form ]-88', 'font-size:13px; background:pink; color:#bf2c9f;', this.form)
      // console.log('%c [ this.model ]-79', 'font-size:13px; background:pink; color:#bf2c9f;', this.model)
      // this.$nextTick(() => {
      //   this.model && this.form.setFieldsValue(pick(this.model, fields))
      // })
    })
  },
  mounted() {
    
  },

  beforeDestroy() {

  },

  methods: {
    ok(){
      this.$emit('ok',  this.form)
    },
    cancel(){
      this.$emit('cancel')
    }
  },
}
</script>
